﻿using System;
using System.Collections.Generic;
using System.IO;

class DeleteAllOddLines
{
    static void Main()
    {
        //Exercise 9.
        //Write a program that deletes from given text file all odd lines. The result should be in the same file.

        StreamReader reader = new StreamReader(@"C:\Users\Toni\Desktop\Test Delete.txt");
        StreamWriter writer = new StreamWriter(@"C:\Users\Toni\Desktop\Test Delete Result.txt");

        List<string> even = new List<string>();

        try
        {
            string line = reader.ReadLine();
            int lineNumber = 0;
            while (line != null)
            {
                lineNumber++;
                if (lineNumber % 2 != 0)
                {
                    even.Add(line);
                }                
                line = reader.ReadLine();                
            }
        }
        finally
        {
            reader.Close();            
        }
        using (writer)
        {
            for (int i = 0; i < even.Count; i++)
            {
                writer.Write(even[i]);
                writer.WriteLine();
            }
        }
    }
}

